package com.example.photography.fragment.home;

import android.text.TextUtils;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.TextView;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.example.photography.R;
import com.example.photography.adapter.home_recommed.ActicleAdapter;
import com.example.photography.bean.ArticleBean2;
import com.example.photography.common.AppNetConfig;
import com.example.photography.common.BaseFragment;
import com.loopj.android.http.RequestParams;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

public class Home_Artaicle extends BaseFragment {
    @BindView(R.id.et_search)
    EditText etSearch;
    @BindView(R.id.tv_publish)
    TextView tvPublish;
    @BindView(R.id.lv_article)
    ListView lvArticle;
    private List<ArticleBean2> articleBeans = new ArrayList<>();
    private ActicleAdapter acticleAdapter;

    @Override
    protected RequestParams getParams() {
        return null;
    }

    @Override
    protected String getUrl() {
        return AppNetConfig.article_all;
    }

    @Override
    protected void initData(String content) {
        if (TextUtils.isEmpty(content)) {//数据为空
            return;
        }

        JSONObject jsonObject = JSON.parseObject(content);
        int status = jsonObject.getInteger("status");
        if (status == 202) {
            String data = jsonObject.getString("data");
            //封装转json数据
            articleBeans = JSONObject.parseArray(data, ArticleBean2.class);
            initView();
        } else {

        }
    }

    private void initView() {
        acticleAdapter = new ActicleAdapter(articleBeans, getActivity());
        lvArticle.setAdapter(acticleAdapter);
    }

    @Override
    public int getLayoutId() {
        return R.layout.home_article;
    }
}
